package o;

import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.DialogInterface.OnKeyListener;
import android.os.IBinder;
import android.view.KeyEvent;
import android.view.KeyEvent.DispatcherState;
import android.view.View;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import androidx.appcompat.view.menu.ListMenuPresenter;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import o.bn.d;

public class bk implements OnKeyListener, OnClickListener, OnDismissListener, d {
    private d ˋ;
    private bd ˎ;
    private af ˏ;
    ListMenuPresenter ॱ;

    public bk(bd bdVar) {
        this.ˎ = bdVar;
    }

    public void ˊ(IBinder iBinder) {
        bd bdVar = this.ˎ;
        af.d dVar = new af.d(bdVar.ᐝ());
        this.ॱ = new ListMenuPresenter(dVar.ˎ(), ah$j.ˊॱ);
        this.ॱ.ˎ((d) this);
        this.ˎ.ˊ(this.ॱ);
        dVar.ˊ(this.ॱ.ˊ(), this);
        View ॱᐝ = bdVar.ॱᐝ();
        if (ॱᐝ != null) {
            dVar.ˏ(ॱᐝ);
        } else {
            dVar.ˊ(bdVar.ˋॱ()).ॱ(bdVar.ˏॱ());
        }
        dVar.ˎ(this);
        this.ˏ = dVar.ˋ();
        this.ˏ.setOnDismissListener(this);
        LayoutParams attributes = this.ˏ.getWindow().getAttributes();
        attributes.type = 1003;
        if (iBinder != null) {
            attributes.token = iBinder;
        }
        attributes.flags |= WXMediaMessage.MINI_PROGRAM__THUMB_LENGHT;
        this.ˏ.show();
    }

    public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
        if (i == 82 || i == 4) {
            Window window;
            View decorView;
            DispatcherState keyDispatcherState;
            if (keyEvent.getAction() == 0 && keyEvent.getRepeatCount() == 0) {
                window = this.ˏ.getWindow();
                if (window != null) {
                    decorView = window.getDecorView();
                    if (decorView != null) {
                        keyDispatcherState = decorView.getKeyDispatcherState();
                        if (keyDispatcherState != null) {
                            keyDispatcherState.startTracking(keyEvent, this);
                            return true;
                        }
                    }
                }
            } else if (keyEvent.getAction() == 1 && !keyEvent.isCanceled()) {
                window = this.ˏ.getWindow();
                if (window != null) {
                    decorView = window.getDecorView();
                    if (decorView != null) {
                        keyDispatcherState = decorView.getKeyDispatcherState();
                        if (keyDispatcherState != null && keyDispatcherState.isTracking(keyEvent)) {
                            this.ˎ.ˏ(true);
                            dialogInterface.dismiss();
                            return true;
                        }
                    }
                }
            }
        }
        return this.ˎ.performShortcut(i, keyEvent, 0);
    }

    public void ॱ() {
        if (this.ˏ != null) {
            this.ˏ.dismiss();
        }
    }

    public void onDismiss(DialogInterface dialogInterface) {
        this.ॱ.ˏ(this.ˎ, true);
    }

    public void ॱ(bd bdVar, boolean z) {
        if (z || bdVar == this.ˎ) {
            ॱ();
        }
        if (this.ˋ != null) {
            this.ˋ.ॱ(bdVar, z);
        }
    }

    public boolean ˎ(bd bdVar) {
        if (this.ˋ != null) {
            return this.ˋ.ˎ(bdVar);
        }
        return false;
    }

    public void onClick(DialogInterface dialogInterface, int i) {
        this.ˎ.ˎ((bj) this.ॱ.ˊ().getItem(i), 0);
    }
}
